package com.cze.service.impl;

import com.cze.mapper.PersonMapper;
import com.cze.service.PersonService;
import com.cze.vo.Person;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户管理实现类
 */
@Service
public class PersonServiceImpl implements PersonService {
    private PersonMapper personMapper;

    @Resource(name = "personMapper")
    public void setpersonMapper(PersonMapper personMapper) {
        this.personMapper = personMapper;
    }

    /**
     * 登录校验
     * @param person
     * @return 登陆成功-true，密码错误、用户不存在-false
     */
    @Override
    public boolean signIn(Person person) {
        Person person1 = personMapper.findByID(person.getId());
        return person1 != null && person1.getPassword().equals(person.getPassword());

    }

    /**
     * 注册
     * @param person
     * @return 注册成功-true，用户已存在-flase
     */
    @Override
    public boolean signUp(Person person) {
        return personMapper.add(person) == 1;
    }

    /**
     * 修改用户信息
     * @param person
     * @return 修改成功-true，无此用户-false
     */
    @Override
    public boolean modify(Person person) {
        return personMapper.update(person) == 1;
    }

    /**
     * 销毁用户
     * @param personID
     * @return 销毁成功-true，无此用户-false
     */
    @Override
    public boolean destroy(String personID) {
        return personMapper.delete(personID) == 1;
    }

    @Override
    public Person findByID(String personID) {
        return personMapper.findByID(personID);
    }
}
